/**
 * @program: LeetCode
 * @description: LeetCode : 剑指 Offer II 004. 只出现一次的数字
 * @author: WXY
 * @create: 2022-12-11 20:04
 * @Version 1.0
 **/


public class Num_offer2_004_singleNumber {
    public static int singleNumber(int[] nums) {
        if (nums.length == 0) return 0;
        int[] ans = new int[32];
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j < 32; j++) {
                ans[j] += nums[i] & 1;
                nums[i] >>= 1;
            }
        }
        int res = 0;
        for (int i = 0; i < 32; i++) {
            res += (ans[i] % 3) * (1 << i);
        }
        return res;
    }
}
